package io.github.frailty9.crserver.config

import com.mybatisflex.annotation.KeyType
import com.mybatisflex.core.FlexGlobalConfig
import com.mybatisflex.core.keygen.KeyGeneratorFactory
import io.github.frailty9.crserver.utils.IdGeneratorImpl
import org.noear.solon.annotation.Bean
import org.noear.solon.annotation.Configuration

@Configuration
class MybatisFlexConfig {

    @Bean
    fun flexGlobalConfig() {
        val flexGlobalConfig = FlexGlobalConfig.getDefaultConfig()
        // 注册雪花ID生成器, 作为默认ID生成器
        KeyGeneratorFactory.register("MySnowflake", IdGeneratorImpl())
        val keyConfig = FlexGlobalConfig.KeyConfig()
        keyConfig.keyType = KeyType.Generator
        keyConfig.value = "MySnowflake"
        keyConfig.isBefore = true
        flexGlobalConfig.keyConfig = keyConfig
    }
}
